<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>测试promise</title>
</head>
<body>
<script src="./05customePromise.js"></script>
<script>
  /*const p = new MyPromise((resolve, reject) => {
      setTimeout(() => {
          resolve('成功');
          console.log('同步代码执行');
      }, 200);
  });
  p.then(value => {
      console.log("onResolved1:", value)
  }, reason => {
      console.log('onRejected1:', reason)
  });
  p.then(value => {
      console.log("onResolved2:", value)
  }, reason => {
      console.log('onRejected2:', reason)
  });*/


  /*new MyPromise(resolve => {
      setTimeout(() => {
          resolve('成功');
          console.log('同步代码执行');
      }, 200);
  }).then(value => {
      console.log('resolve1:', value);
      throw new Error('resolve1 throw')
  }).then(value => {
      console.log('resolve2:', value);
  }, reason => {
      console.log('reject2:', reason);
  }).then(value => {
      console.log('resolve3:', value);
  })*/

  /*
  const p1 = MyPromise.resolve(4);
  const p2 = MyPromise.resolve(MyPromise.resolve(5));
  const p3 = MyPromise.resolve(MyPromise.reject(6));
  p1.then(value => {
      console.log(value)
  });
  p2.then(value => {
      console.log(value)
  });
  p3.then().catch(reason => {
      console.log(reason)
  })*/

  const p1 = MyPromise.resolve(4);
  const p2 = MyPromise.resolve(MyPromise.resolve(5));
  const p0 = new MyPromise((resolve) => {
    setTimeout(() => {
      resolve(77)
    }, 1000)
  });
  MyPromise.all([p0, p1, p2]).then(values => {
    console.log('all:', values);
  }).catch(reason => {
    console.log('all failed:', reason);
  });
  MyPromise.race([p0, p2, 666]).then(value => {
    console.log('race:', value);
  });

  const pDelay = MyPromise.resolveDelay(50, 3000);
  pDelay.then(value => {
    console.log('delay:', value)
  });
  const pDelay2 = MyPromise.rejectDelay(13, 3000);
  pDelay2.catch(reason => {
    console.error(reason)
  })
</script>
</body>
</html>
